9  Online Appendix B

9.1 Setup

9.1.1 Install Packages

We install the following packages using the groundhog package manager to increase computational reproducibility.

if (!requireNamespace("groundhog", quietly = TRUE)) {
    install.packages("groundhog")
    library("groundhog")
}

pkgs <- c("magrittr", "data.table", "stringr", "lubridate", "knitr", "glue",
          "sandwich", "lmtest",
          "ggplot2", "ggpubr", "rstatix", "patchwork")

groundhog::groundhog.library(pkg = pkgs,
                             date = "2023-09-25")

9.1.2 Read Data

# data <- data.table::fread(file = "../data/processed/full.csv")
data <- readRDS(file="../data/processed/full.Rda")

9.1.3 Manipulate Data

[Shall we add this code chunk to the pre-processing?]

data[, communication := as.factor(communication)]
data[, communication := factor(communication, levels = c("point", "both","interval"))]
data[, stage := as.factor(stage)]
data[, stage := factor(stage, levels = c("1", "2"))]

9.1.4 Design

We define some design features in the following:

colors <- c("#F3B05C", "#1E4A75", "#65B5C0", "#AD5E21")

layout <- theme(panel.background = element_rect(fill = "white"),
                legend.key = element_rect(fill = "white"),
                panel.grid.major.y = element_line(colour = "grey", 
                                                  linewidth = 0.25),
                axis.ticks.y = element_blank(),
                panel.grid.major.x = element_blank(),
                axis.line.x.bottom = element_line(colour = "#000000", 
                                                  linewidth = 0.5),
                axis.line.y.left = element_blank(),
                plot.title = element_text(size = rel(1))
)

9.1.5 Helper Function

plot_bars <- function(response = "E", surprise_sub = NA, limits = ylim(-0.1, 100.1)){
  
  if(response == "E1"|response == "E2"|response == "E3"){
      y_1 = 73
      y_2 = 55
    } else {
      y_1 = 73
      y_2 = 63
    }
  
  if(!is.na(surprise_sub)){
    # Plot bottom panels
    tmp <- data[surprise == surprise_sub]
    names(tmp)[names(tmp) == response] <- 'outcome'
    
    if(surprise_sub){
      title <- "Surprising Condition"
    } else {
      title <- "Confirming Condition"
    }
    
    test_stats_1 <- tmp %>% 
      group_by(communication) %>%
      wilcox_test(formula = outcome ~ stage,
                  paired = T) %>% 
      adjust_pvalue(method = "none") %>%
      add_significance(p.col = "p.adj",
                       cutpoints = c(0, 0.01, 0.05, 0.1, 1),
                       symbols = c( "***", "**", "*", "ns")) %>%
      as.data.table()
    
    
    test_stats_2 <- tmp %>% 
      group_by(stage) %>%
      wilcox_test(formula = outcome ~ communication) %>% 
      adjust_pvalue(method = "none") %>%
      add_significance(p.col = "p.adj",
                       cutpoints = c(0, 0.01, 0.05, 0.1, 1),
                       symbols = c( "***", "**", "*", "ns")) %>%
      as.data.table()
    test_stats_2 <- test_stats_2[stage == 2]
    
    plot_bottom <- ggplot(data = tmp,
           mapping = aes(x = as.factor(communication),
                         y = outcome)) +
        geom_bar(position = "dodge", 
                 stat = "summary", 
                 fun = "mean",
                 fill = colors[2]) + 
      limits +
      scale_y_continuous(limits = c(0, 100), expand = c(0, NA)) +
      layout +
      stat_pvalue_manual(data = test_stats_2,
                         label = "{p} ({p.adj.signif})", 
                         step.group.by = "stage",
                         tip.length = 0, 
                         step.increase = 0.1, 
                         y.position = y_1) +
      stat_pvalue_manual(data = test_stats_1,
                         label = "{p} ({p.adj.signif})",
                         y.position = y_2,
                         tip.length = 0,
                         x = "communication") +
      labs(title = title,
           x = "Communication",
           y = glue("{response}"))
    
    rm(tmp)
    
    plot_bottom
  } else {
    # Plot the top panel
    tmp <- data
    names(tmp)[names(tmp) == response] <- 'outcome'
    
    title <- "Both Conditions"
    
    test_stats_1 <- tmp %>% 
      group_by(surprise) %>%
      wilcox_test(formula = outcome ~ stage,
                  paired = T) %>% 
      adjust_pvalue(method = "none") %>%
      add_significance(p.col = "p.adj",
                       cutpoints = c(0, 0.01, 0.05, 0.1, 1),
                       symbols = c( "***", "**", "*", "ns")) %>%
      as.data.table()
    
    
    test_stats_2 <- tmp %>% 
      group_by(stage) %>%
      wilcox_test(formula = outcome ~ surprise) %>% 
      adjust_pvalue(method = "none") %>%
      add_significance(p.col = "p.adj",
                       cutpoints = c(0, 0.01, 0.05, 0.1, 1),
                       symbols = c( "***", "**", "*", "ns")) %>%
      as.data.table()
    test_stats_2 <- test_stats_2[stage == 2]
    
    
    plot_top <- ggplot(data = tmp,
           mapping = aes(x = as.factor(surprise),
                         y = outcome)) +
        geom_bar(position = "dodge", 
                 stat = "summary", 
                 fun = "mean",
                 fill = colors[2]) + 
      limits +
      scale_y_continuous(limits = c(0, 100), expand = c(0, NA)) +
      layout +
      stat_pvalue_manual(data = test_stats_2,
                         label = "{p} ({p.adj.signif})", 
                         step.group.by = "stage",
                         tip.length = 0, 
                         step.increase = 0.1, 
                         y.position = y_1) +
      stat_pvalue_manual(data = test_stats_1,
                         label = "{p} ({p.adj.signif})",
                         y.position = y_2,
                         tip.length = 0,
                         x = "surprise") +
      labs(title = title,
           x = " Surprising Condition",
           y = glue(" {response}"))
    
    rm(tmp)
    
    plot_top
  }
}

9.2 Figure OB.1

To create Figure fig-OB1 (and the other figures), we use the wrapper function defined above. We’ll call several times in what follows. As all the other figures presented in this document, Figure fig-OB1 consists of three panels, top, left, and right that are relatively similar. We thus, save both space and sources of error by creating a wrapper function plot_bars() that creates bar plots and annotates them with test statistics.

top   <- plot_bars(response = "E1", surprise_sub = NA)
left  <- plot_bars(response = "E1", surprise_sub = FALSE)
right <- plot_bars(response = "E1", surprise_sub = TRUE)

(top / (left | right) & theme(legend.position = "bottom")) + plot_layout(guides = "collect")

Figure 9.1: Means of the matching probabilities for event E1 separated by treatments and part 1 and part 2. P-values of Wilcoxon signed-rank test comparing part 1 and 2 directly above the mean values. P-values of Wilcoxon–Mann–Whitney test comparing part 2 of different treatments at the top. Note: ∗p<0.10, ∗∗p<0.05, ∗∗∗p<0.01, ns: not significant

9.3 Figure OB.2

Next, we use the wrapper function again but visualize another outcome using the response == E2 argument.

top   <- plot_bars(response = "E2", surprise_sub = NA)
left  <- plot_bars(response = "E2", surprise_sub = FALSE)
right <- plot_bars(response = "E2", surprise_sub = TRUE)

(top / (left | right) & theme(legend.position = "bottom")) + plot_layout(guides = "collect")

Figure 9.2: Means of the matching probabilities for event E2 separated by treatments and part 1 and part 2. P-values of Wilcoxon signed-rank test comparing part 1 and 2 directly above the mean values. P-values of Wilcoxon–Mann–Whitney test comparing part 2 of different treatments at the top. Note: ∗p<0.10, ∗∗p<0.05, ∗∗∗p<0.01, ns: not significant

9.4 Figure OB.3

Next, we use the wrapper function again but visualize another outcome using the response == E3 argument.

top   <- plot_bars(response = "E3", surprise_sub = NA)
left  <- plot_bars(response = "E3", surprise_sub = FALSE)
right <- plot_bars(response = "E3", surprise_sub = TRUE)

(top / (left | right) & theme(legend.position = "bottom")) + plot_layout(guides = "collect")

Figure 9.3: Means of the matching probabilities for event E3 separated by treatments and part 1 and part 2. P-values of Wilcoxon signed-rank test comparing part 1 and 2 directly above the mean values. P-values of Wilcoxon–Mann–Whitney test comparing part 2 of different treatments at the top. Note: ∗p<0.10, ∗∗p<0.05, ∗∗∗p<0.01, ns: not significant

9.5 Figure OB.4

Next, we use the wrapper function again but visualize another outcome using the response == E12 argument.

top   <- plot_bars(response = "E12", surprise_sub = NA)
left  <- plot_bars(response = "E12", surprise_sub = FALSE)
right <- plot_bars(response = "E12", surprise_sub = TRUE)

(top / (left | right) & theme(legend.position = "bottom")) + plot_layout(guides = "collect")

Figure 9.4: Means of the matching probabilities for event E12 separated by treatments and part 1 and part 2. P-values of Wilcoxon signed-rank test comparing part 1 and 2 directly above the mean values. P-values of Wilcoxon–Mann–Whitney test comparing part 2 of different treatments at the top. Note: ∗p<0.10, ∗∗p<0.05, ∗∗∗p<0.01, ns: not significant

9.6 Figure OB.5

Next, we use the wrapper function again but visualize another outcome using the response == E13 argument.

top   <- plot_bars(response = "E13", surprise_sub = NA)
left  <- plot_bars(response = "E13", surprise_sub = FALSE)
right <- plot_bars(response = "E13", surprise_sub = TRUE)

(top / (left | right) & theme(legend.position = "bottom")) + plot_layout(guides = "collect")

Figure 9.5: Means of the matching probabilities for event E13 separated by treatments and part 1 and part 2. P-values of Wilcoxon signed-rank test comparing part 1 and 2 directly above the mean values. P-values of Wilcoxon–Mann–Whitney test comparing part 2 of different treatments at the top. Note: ∗p<0.10, ∗∗p<0.05, ∗∗∗p<0.01, ns: not significant

9.7 Figure OB.6

Next, we use the wrapper function again but visualize another outcome using the response == E23 argument.

top   <- plot_bars(response = "E23", surprise_sub = NA)
left  <- plot_bars(response = "E23", surprise_sub = FALSE)
right <- plot_bars(response = "E23", surprise_sub = TRUE)

(top / (left | right) & theme(legend.position = "bottom")) + plot_layout(guides = "collect")

Figure 9.6: Means of the matching probabilities for event E23 separated by treatments and part 1 and part 2. P-values of Wilcoxon signed-rank test comparing part 1 and 2 directly above the mean values. P-values of Wilcoxon–Mann–Whitney test comparing part 2 of different treatments at the top. Note: ∗p<0.10, ∗∗p<0.05, ∗∗∗p<0.01, ns: not significant